package fr.mma.livraison;
import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import fr.mma.livraison.controler.Factory;
import fr.mma.livraison.controler.MainController;
import fr.mma.livraison.controler.OrderType;

@SuppressWarnings("serial")
public class DevListServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		resp.setContentType("application/json");
		MainController mainController =  new MainController();
		Gson gson = new Gson();
		String orderBy = req.getParameter("sortBy");
		String json;
		if(orderBy == null) {
			json = gson.toJson(mainController.getAllDev());  
		} else {
			json = gson.toJson(Factory.build(mainController.getAllDev(OrderType.getByValue(orderBy)))); 
		}
		resp.getWriter().println(json);
	}
}
